package com.xpqh.ksg.modular.sys.controller;

import com.xpqh.ksg.base.BaseController;
import com.xpqh.ksg.base.BaseResponseDTO;
import com.xpqh.ksg.common.enums.result.BizExceptionEnum;
import com.xpqh.ksg.common.persistence.model.KsgSysFileEntity;
import com.xpqh.ksg.modular.sys.service.KsgSysFileService;
import common.enums.FilePathEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/ksg/sys/file")
public class KsgSysFileController extends BaseController {

    @Autowired
    private KsgSysFileService ksgSysFileService;

    /**
     * 文件上传接口
     * 
     * @param file 上传的文件
     * @param fileType 文件类型，可选值参考 FilePathEnum
     * @return 文件上传结果
     */
    @PostMapping("/upload")
    public BaseResponseDTO uploadFile(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "fileType", required = false, defaultValue = "SYSTEM_DEFAULT") String fileType) {
        try {
            KsgSysFileEntity fileEntity = ksgSysFileService.uploadFile(getUserId(), file, FilePathEnum.valueOf(fileType));
            return renderResultOk(fileEntity);
        } catch (Exception e) {
            return renderResult(BizExceptionEnum.SERVER_ERROR);
        }
    }
} 

